package library;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.util.HashMap;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.html.HTMLDocument.Iterator;

public class TextPane extends JPanel {

	private HashMap<String, JTextField> fields = new HashMap<String, JTextField>();
	private String[] names;
	
	public TextPane(String[] text, JTextField... field) {

		this.setLayout(new GridLayout(field.length * 2, 1));
		names = text;
		
		for (int i = 0; i < field.length; i++) {
			fields.put(text[i], field[i]);
			JLabel label = new JLabel(text[i]);
			this.add(label);
			this.add(field[i]);
		}

		// TODO Auto-generated constructor stub
	}

	public String getFieldText(String name) {
		return fields.get(name).getText();
	}

	public JTextField getField(String name) {
		return fields.get(name);
	}
	
	
	/**
	 * Clears all text fields.
	 */
	public void clearTextFields(){
		for ( int i = 0; i < names.length; i++) {
			if (fields.containsKey(names[i])) {
				fields.get(names[i]).setText("");
			}
		}
	}
}
